package com.huadao.cart_ccs.experiment.progressOverview;

import com.huadao.cart_ccs.common.ExperimentStageManager;
import com.huadao.cart_ccs.common.ProjectManager;
import com.huadao.cart_ccs.data.bo.ExperimentStage;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.Operation;
import com.huadao.cart_ccs.greendao.gen.ExperimentStageDao;
import com.huadao.cart_ccs.greendao.gen.OperationDao;

import java.util.List;

public class ProgressOverViewPresenter extends IProgressOverViewContract.IProgressOverViewPresenter {

    private ExperimentStageDao experimentStageDao;
    private OperationDao operationDao;

    public ProgressOverViewPresenter(IProgressOverViewContract.IProgressOverViewView baseView) {
        attachView(baseView);
        experimentStageDao=GreenDaoManager.getInstance().getNoCacheSession().getExperimentStageDao();
        operationDao=GreenDaoManager.getInstance().getNoCacheSession().getOperationDao();
    }

    @Override
    public void getHappenedStageList() {
        List<ExperimentStage> experimentStageList=experimentStageDao.queryBuilder().where(ExperimentStageDao.Properties.ProjectId.eq(ProjectManager.getInstance().getProjectId())).list();
        baseView.onGetHappenedStageList(experimentStageList);
    }

    @Override
    public void getOperateList() {
        List<Operation> operationList=operationDao.queryBuilder().where(OperationDao.Properties.ProjectId.eq(ProjectManager.getInstance().getProjectId()),OperationDao.Properties.StageId.eq(baseView.getCurrentStage().getId())).list();
        baseView.onGetOperateList(operationList);
    }

    @Override
    public void setNewName(String newName) {
        boolean isSucc=ExperimentStageManager.getInstance().setNameForCurrentStage(newName);
        if(isSucc){
            baseView.setNewNameSucc(newName);
        }else {
            baseView.setNewNameFailed();
        }
    }
}
